home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / tjgold.zip / INSTALL.004 / FGUSER12.TXT < prev    next >
Text File  |  1995-05-29  |  21KB  |  547 lines

  1.                              Managing the Desktop
  2.  
  3.                                     "Oh, London is a fine town, a very
  4.                                      famous city where all the streets
  5.                                      are paved with gold and all the
  6.                                      maidens pretty"
  7.                                  George Coleman the younger, 1762-1836
  8.                                              The Heir at Law
  9.  
  10. Introduction
  11.  
  12.           A desktop application typically has a pull-down menu, a status
  13.      bar, and a main area (in between) where windows are displayed. One
  14.      of the best known desktop applications (for us programmer types) is
  15.      Borland's integrated development environment for C and Pascal.
  16.  
  17.           The unit GOLDDESK provides a set of elegant tools to make it
  18.      easy for you to create a sophisticated desktop application. We
  19.      don't need no stinkin' Turbo Vision!! (Just kidding David.)
  20.  
  21.  
  22.      Figure 12.1
  23.      A Typical
  24.      Desktop
  25.  
  26.  
  27. Ingredients of a Desktop
  28.  
  29.           A full desktop includes a pull-down menu, a status bar and one
  30.      or more windows. Gold also allows you to define a partial desktop
  31.      which has either a menu or a status bar. Having built the
  32.      individual desktop components, the desktop is constructed using the
  33.      DeskAssignxxx functions.
  34.  
  35. The Pull-down Menu
  36.  
  37.           The desktop utilizes a standard Gold pull-down menu. If you
  38.      are not familiar with these menus, read Chapter 11.
  39.  
  40.           Having constructed a menu, it can be added to the desktop with
  41.      the procedure DeskAssignMainMenu. This procedure is passed the
  42.      MenuBar variable which defines the menu. For example:
  43.  
  44.           DeskAssignMainMenu(MainMenu);
  45.  
  46.      That's all there is to it.
  47.  
  48.           If, for some strange reason, you want to continue using the
  49.      desktop, but want the menu removed, just call the procedure
  50.      DeskRemoveMainMenu.
  51.  
  52. The Status Bar
  53.  
  54.           At status bar is a single row of options positioned on the
  55.      bottom line of the display. It's like a menu bar without any
  56.      popups. The code used to create a status bar is exactly the same as
  57.      the code to create a menu bar.
  58.  
  59.           If you want to add a status bar to the desktop, create a
  60.      variable of type MenuBar, initialize the variable with InitBar, and
  61.      use the procedure DeskAssignStatusBar to add the status bar to the
  62.      desktop. The following code fragment illustrates this approach:
  63.  
  64.           var StatusBar: bar;
  65.           begin
  66.              InitBar(StatusBar);
  67.              BarAddItem(StatusBar,'~F1~ Help',1001,315,315,'',nil);
  68.              BarAddItem(StatusBar,'~Alt+X~ Exit the demo',999,301,
  69.                                                 301,'',nil);
  70.              DeskAssignStatusBar(Statusbar);
  71.              ...
  72.           end;
  73.  
  74.           The status bar can be removed by calling the procedure
  75.      DeskRemoveStatusBar.
  76.  
  77. The Background
  78.  
  79.           Every desktop has a background; this is the main area of the
  80.      screen which extends from the pull-down menu to the status bar.
  81.      Normally, this area is filled with a single character to provide a
  82.      plain wallpaper.
  83.  
  84.           You can change the default appearance of the background by
  85.      assigning a different character to the variable DeskVars.BackChar.
  86.      Also, you can change the background color by using the GoldSetColor
  87.      procedure and assigning a new value to the DeskBack element. For
  88.      example:
  89.  
  90.           DeskVars.BackChar := chr(179)
  91.           GoldSetColor(DeskBack,WhiteonGreen);
  92.  
  93.           Gold provides a way for you to create more sophisticated
  94.      backgrounds. All you have to do is create a procedure following
  95.      some specific rules, and then call the DeskAssignPaintProc
  96.      procedure to instruct Gold to call your procedure every time the
  97.      background needs to be repainted.
  98.  
  99.           For a procedure to be eligible as a paint procedure it must
  100.      adhere to the following rules:
  101.  
  102.           The procedure must be declared as a far procedure at the root
  103.           level. Refer to section Understanding Hooks in Chapter 3 for
  104.           further information.
  105.  
  106.           The procedure must be declared with no parameters.
  107.  
  108.      The following procedure declaration follows these rules:
  109.  
  110.           {$F+}
  111.           procedure CustomBgnd;
  112.           begin
  113.              {some code}
  114.           end; {CustomBgnd}
  115.           {$F-}
  116.  
  117.           The following procedure is then called to instruct Gold to
  118.      call your procedure every time the desktop needs painting:
  119.  
  120.      DeskAssignPaintProc (Hook:KeyPressedHook);
  121.  
  122.           Instructs Gold to call the specified procedure every time Gold
  123.      needs to draw the background.
  124.  
  125.           If, subsequently, you want to remove the custom paint
  126.      procedure, execute the command DeskRemovePaintProc.
  127.  
  128.           Run the demo program DEMDESK7.PAS to see a custom paint
  129.      procedure in action.
  130.  
  131. Responding to User Input
  132.  
  133.           A desktop is simply a standard way to garner user input. The
  134.      user can select items from the menu, click on the status, or press
  135.      hotkeys. The application must then respond to this input and act
  136.      accordingly. So much for the theory of desktops.
  137.  
  138.           Gold takes care of managing the user input. You don't need to
  139.      explicitly invoke the menu or status bar; Gold takes care of it for
  140.      you. If the keystroke or mouse activity is directed towards the
  141.      pull-down menu, the keystroke will be passed to the menu for
  142.      processing. Similarly, status bar-related keystrokes will be passed
  143.      to the status bar for processing. If the user clicks on the top
  144.      window (if there is a window visible), the keystroke is passed to
  145.      the window for processing. Finally, if the user clicks on a window
  146.      without focus, the window is moved to the top, i.e. given focus.
  147.  
  148. Assigning an Action Procedure
  149.  
  150.           Every item in the menu and status bar has an ID -- you
  151.      assigned the ID as one of the arguments in BarAddItem and
  152.      PopAddItem. When the user selects an item from the desktop, Gold
  153.      passes the ID of the selected item to a user-defined action
  154.      procedure.
  155.  
  156.           All you have to do is create a procedure following some
  157.      specific rules, and then call the DeskAssignActionProc procedure to
  158.      instruct Gold to call your procedure every time the user makes a
  159.      selection.
  160.  
  161.           For a procedure to be eligible as an action procedure it must
  162.      adhere to the following rules:
  163.  
  164.           The procedure must be declared as a far procedure at the root
  165.           level. Refer to the section Understanding Hooks in Chapter 3
  166.           for further information.
  167.  
  168.           The procedure must be declared with two passed parameters. The
  169.           first parameter is an integer and a variable parameter of type
  170.           DAction.
  171.  
  172.      The following procedure declaration follows these rules:
  173.  
  174.           {$F+}
  175.           procedure MyActionProc(Choice:integer;
  176.                     var Action:DAction);
  177.           {}
  178.           begin
  179.              case Choice of
  180.                 .....
  181.              end;
  182.           end; { MyActionProc }
  183.           {$F-}
  184.  
  185.           The following procedure is then called to instruct Gold to
  186.      call your procedure after each desktop input:
  187.  
  188.      DeskAssignActionProc(Aproc:DeskActionProc);
  189.  
  190.           Instructs Gold to call the specified procedure every time the
  191.      user makes a status bar or menu selection from the desktop.
  192.  
  193. Writing the Action procedure
  194.  
  195.           The first parameter passed to the action procedure is the ID
  196.      of the item selected from the menu or status bar. The body of the
  197.      action procedure usually takes the form of a case statement which
  198.      branches to another part of the program based on the user
  199.      selection.
  200.  
  201.           The second parameter passed to the action procedure is a
  202.      variable parameter of type DAction, which is an enumerated type
  203.      declared in GOLDDESK as follows:
  204.  
  205.           DAction = (DFinished, Descaped, DRepaint, DNone, DCloseTop,
  206.                                    DCloseAll,DStop1..DStop99);
  207.  
  208.           By updating this variable with a value (other than DNone) you
  209.      can instruct Gold to take some form of action. For example, if you
  210.      update the variable with a value of DRepaint, Gold will
  211.      automatically repaint the menu, status bar, background, and every
  212.      window. The following table elaborates on the actions taken buy
  213.      Gold for each of the return values:
  214.  
  215.      DAction Value   Meaning
  216.  
  217.      DFinished       Ends the desktop session and returns the code
  218.                      DFinished.
  219.      DEscaped        Ends the desktop session and returns the code
  220.                      DEscaped.
  221.      DRepaint        Forces a repaint of the desktop and all the
  222.                      windows.
  223.      DNone           No action is taken - this is the default value
  224.                      when the action procedure doesn't modify the
  225.                      variable.
  226.      DCloseTop       Forces the top window to close.
  227.      DCloseAll       Forces all the windows to close.
  228.      DStop1..DStop99 Ends the desktop session and returns the
  229.                      appropriate stop code.
  230.  
  231. Starting a Desktop Session
  232.  
  233.           Having assigned the menu, status bar and action procedure, you
  234.      are ready to launch the desktop and wait for user input. All you
  235.      have to do is call the function DeskProcessInput. This function
  236.      returns the DAction which caused the session to close (see the
  237.      above table).
  238.  
  239. A Simple Desktop Example
  240.  
  241.           Listed below is the entire source code for DEMDESK1.PAS which
  242.      implements a minimalist desktop. Although the desktop doesn't have
  243.      too many features, it does illustrate all the important principles
  244.      of creating a desktop application.
  245.  
  246.           var MainMenu: Bar;
  247.               SubMenu: PopUp;
  248.               Action : dAction;
  249.  
  250.           procedure DefineSubMenu;
  251.           {}
  252.           begin
  253.              InitPopUp(SubMenu);
  254.              with SubMenu do
  255.              begin
  256.                 PopUpAddItem(SubMenu,'~A~bout',101,65,
  257.                              'Show version...ation',nil);
  258.                 PopUpAddItem(SubMenu,'E~x~it',999,88,
  259.                              '~Exit~ this little demo',nil);
  260.              end;
  261.           end; { DefineSubMenu }
  262.  
  263.           procedure DefineMainMenu;
  264.           {}
  265.           begin
  266.              InitBar(MainMenu);
  267.              BarAddItem(MainMenu,'~C~hoices',100,67,302,
  268.                         'Select one of two menu options',
  269.                          @SubMenu);
  270.              MainMenu.Style := 2;
  271.           end; { DefineMainMenu }
  272.  
  273.           procedure DisposeMenus;
  274.           {}
  275.           begin
  276.              DestroyBar(MainMenu);
  277.              DestroyPopUp(SubMenu);
  278.           end; { DisposeMenus }
  279.  
  280.           {$F+}
  281.           procedure MyActionProc(Choice:integer;var Action:DAction);
  282.           {}
  283.           begin
  284.              case Choice of
  285.                101: PromptOK(' The Gold Desktop ',
  286.                     '^Copyright 1995 TechnoJock Software, Inc.|'
  287.                     +'^All Rights Reserved');
  288.                999: Action := DFinished;
  289.              end;
  290.           end; { MyActionProc }
  291.           {$F-}
  292.  
  293.           begin
  294.              DefineSubMenu;
  295.              DefineMainMenu;
  296.              DeskAssignMainMenu(MainMenu);
  297.              DeskAssignActionProc(MyActionProc);
  298.              MouseShow(true);
  299.              CursorOff;
  300.              Action := DeskProcessInput;
  301.              CursorOn;
  302.              MouseShow(false);
  303.              DisposeMenus;
  304.           end.
  305.  
  306. Launching Desktop Windows
  307.  
  308.           A desktop is really a standard framework for launching windows
  309.      or applets. Many of the Gold units include procedures which are
  310.      exclusively designed for launching windows onto the desktop. In
  311.      this section you will learn how to populate the desktop with
  312.      windows.
  313.  
  314. Understanding Modal and Non-Modal Windows
  315.  
  316.           A modal window is a window which disables all other aspects of
  317.      the desktop and forces all input to the window. When a modal window
  318.      is active, the user cannot switch to another window, nor select
  319.      items from the menu or the status bar. Modal windows are ideal for
  320.      error messages or dialogs which require immediate input, e.g. an
  321.      open file dialog.
  322.  
  323.           Non-modal windows, on the other hand, can lose focus and form
  324.      the heart of a true desktop application. Examples of non-modal
  325.      windows include a file browser, calculator and calendar. Borland
  326.      Pascal uses non-modal windows for the edit windows where the source
  327.      code is managed.
  328.  
  329. Launch-able Gold Components
  330.  
  331.           Many of the Gold units include primary procedures which begin
  332.      with the word Run, e.g. RunCalculator, RunBrowse, etc. When the
  333.      object can also be used on a desktop there is a related Launch
  334.      function, e.g. LaunchCalculator, LaunchBrowse.
  335.  
  336.           Listed below is a summary of all the Gold procedures which can
  337.      be used to launch non-modal windows onto the desktop.
  338.  
  339.      LaunchCalendar(StartDate:Dates;Tit:string): byte;
  340.  
  341.           Adds a month-at-a-glance window to the desktop. The arguments
  342.      passed to this procedure are the same as for RunCalendar discussed
  343.      in Chapter 7. The function returns the number (or handle) of the
  344.      newly created window.
  345.  
  346.      LaunchCalculator(Tit:string): byte;
  347.  
  348.           Adds a push-button calculator to the desktop. The arguments
  349.      passed to this procedure are the same as for RunCalculator
  350.      discussed in Chapter 8. The function returns the number (or handle)
  351.      of the newly created window.
  352.  
  353.      LaunchBrowse(var ListDetails: ListCfg;Tit:StrScreen;
  354.                                          CloseProc:ListCloseProc):byte;
  355.  
  356.           Launches a browser for viewing the contents of an array or
  357.      linked list. The arguments passed to this procedure are discussed
  358.      in Chapter 14. The function returns the number (or handle) of the
  359.      newly created window.
  360.  
  361.      LaunchBrowseFile(Fname:PathStr;Tit:StrScreen):byte;
  362.  
  363.           Launches a browser for viewing the contents of a file. The
  364.      arguments passed to this procedure are the same as for
  365.      RunBrowseFile discussed in Chapter 14. The function returns the
  366.      number (or handle) of the newly created window.
  367.  
  368.      LaunchList(var ListDetails: ListCfg;Tit:StrScreen;
  369.                                        CloseProc:ListCloseProc): byte;
  370.  
  371.      Adds a list window to the desktop. The arguments passed to this
  372.      procedure are discussed in Chapter 14. The function returns the
  373.      number (or handle) of the newly created window.
  374.  
  375.      LaunchGrid(var ListDetails: ListCfg;Tit:StrScreen):byte;
  376.  
  377.           Adds a list window to the desktop. The arguments passed to
  378.      this procedure are the same as for RunGrid discussed in Chapter 14.
  379.      The function returns the number (or handle) of the newly created
  380.      window.
  381.  
  382.      LaunchMemo(var MemoDetails: MemoCfg;Tit:StrScreen;
  383.                                       CloseProc:MemoCloseProc): byte;
  384.  
  385.           Adds a memo window to the desktop. The arguments passed to
  386.      this procedure are discussed in Chapter 15. The function returns
  387.      the number (or handle) of the newly created window.
  388.  
  389.      LaunchFormInit(X1,Y1,X2,Y2,style:byte;CloseProc:FormCloseProc):byte
  390.  
  391.      LaunchForm(StartField:byte);
  392.  
  393.           These functions are used to create non-modal IO forms, and are
  394.      discussed in more detail in Chapter 16.
  395.  
  396.  
  397.           The demo files DEMDESK2.PAS to DEMDESK5.PAS illustrate many of
  398.      the above launch functions.
  399.  
  400. Positioning New Windows
  401.  
  402.           Most desktop applications place a new window down and to the
  403.      right of the (old) top window. Complications arise when the top
  404.      window is located near the right or the bottom of the desktop where
  405.      there is insufficient room for the new window.
  406.  
  407.           Gold offers the following two functions to help you calculate
  408.      the dimensions of a new window:
  409.  
  410.      DeskNextWinDim(var X1,Y1,X2,Y2: shortint; MinWidth,MinDepth:
  411.                                                            longint);
  412.  
  413.           Updates the first four parameters with a set of coordinates
  414.      which can be used to size a new window that is about to be added to
  415.      the desktop.
  416.  
  417.      DeskNextWinCoords(var TLX,TLY: byte);
  418.  
  419.           Updates the passed parameters with the appropriate coordinates
  420.      (of the top left of the window) which can be assigned to a new
  421.      window that is about to be added to the desktop.
  422.  
  423. Displaying Modal Windows
  424.  
  425.           There is nothing to stop you from using modal windows on the
  426.      desktop. For example, you might use PromptStr to ask the user to
  427.      input a password. In fact, most desktop applications use both modal
  428.      and non-modal windows. In Borland Pascal, for example, a modal
  429.      window is used to prompt for confirmation during a multiple search
  430.      and replace operation.
  431.  
  432.           However, always remember that a modal window must be removed
  433.      before the user can access the menu, status bar, or other windows.
  434.      So use modal windows sparingly.
  435.  
  436. Adding a Traditional "Window" menu
  437.  
  438.           If you like to conform to Microsoft Windows and DOS desktop
  439.      applications standards, you should consider adding Window and Help
  440.      items to the pull-down menu. The contents of the Help menu is
  441.      application specific, but the Window menu often displays a standard
  442.      set of items (see Figure 12.2).
  443.  
  444.           You create a window pop-up just like any other pop-up -- by
  445.      adding items to a PopUpMenu, and by responding to the menu choices
  446.      in the action procedure. The good news is that you do not have to
  447.      write your own tiling and cascading procedures. GOLDDESK includes
  448.      the following procedures to help with window management:
  449.  
  450.  
  451.      Figure 12.2
  452.      A Standard
  453.      Window Menu
  454.  
  455.  
  456.      DeskCloseAllWindows: boolean;
  457.  
  458.           Closes all the windows on the desktop. If the function returns
  459.      FALSE, one or more window could not be closed. This might occur,
  460.      for example, when an IO form is closed but the value entered into a
  461.      field is not valid.
  462.  
  463.      DeskNextWin;
  464.  
  465.      Changes focus to the next window in the list.
  466.  
  467.      DeskPrevWin;
  468.  
  469.      Changes focus to the previous window in the list.
  470.  
  471.      DeskStretchTopWin: boolean;
  472.  
  473.           Lets the user manually (without the mouse) stretch the window.
  474.      A FALSE is returned if the window cannot be stretched.
  475.  
  476.      DeskZoomTopWin: boolean;
  477.  
  478.           Makes the top window the size of the desktop. A FALSE is
  479.      returned if the window cannot be zoomed.
  480.  
  481.      DeskMoveTopWin: boolean;
  482.  
  483.           Lets the user manually (without the mouse) move the top
  484.      window. A FALSE is returned if the window cannot be moved.
  485.  
  486.      DeskCascade;
  487.  
  488.           Arranges all the windows, cascading from the top left of the
  489.      desktop.
  490.  
  491.      DeskTile: boolean;
  492.  
  493.           Tiles all the windows on the desktop. A FALSE is returned if
  494.      the one or more windows cannot be tiled.
  495.  
  496.      DeskWinList;
  497.  
  498.           Displays a window listing all the files and allows the user to
  499.      change focus.
  500.  
  501.           You can copy and paste the window related code from the demo
  502.      file DEMDESK6.PAS into your own desktop application.
  503.  
  504. Implementing a Hind Hook
  505.  
  506.           A desktop hind hook is a procedure which is called every time
  507.      an input has been processed by the desktop. A hind hook can be used
  508.      to change the grayed status of menu items based on the window with
  509.      focus, for example.
  510.  
  511.           All you have to do is create a procedure following some
  512.      specific rules, and call the DeskAssignHindHook procedure to
  513.      instruct Gold to call your procedure every time some input has been
  514.      processed.
  515.  
  516.           For a procedure to be eligible as a desktop hind hook, it must
  517.      adhere to the following rules:
  518.  
  519.           The procedure must be declared as a far procedure at the root
  520.           level. Refer to the section Understanding Hooks in Chapter 3
  521.           for further information.
  522.  
  523.           The procedure must be declared with no parameters.
  524.  
  525.      The following procedure declaration follows these rules:
  526.  
  527.           {$F+}
  528.           procedure CustomHook;
  529.           begin
  530.              {some code}
  531.           end; {CustomHook}
  532.           {$F-}
  533.  
  534.           The following procedure is then called to instruct Gold to
  535.      call your procedure every time the desktop needs painting:
  536.  
  537.      DeskAssignHindHook (Hook:KeyPressedHook);
  538.  
  539.           Instructs Gold to call the specified procedure every time Gold
  540.      has processed an input to the desktop..
  541.  
  542.           If, subsequently, you want to remove the hind hook procedure,
  543.      execute the command DeskRemoveHindHook.
  544.  
  545.           Run the demo program DEMOVIEW.PAS to see a custom hind hook in
  546.      action.
  547.